export default {
  mounted() {
    this.enableDragging();
  },
  methods: {
    enableDragging() {
      console.log("DraggableMixin enabled");
      const button = document.getElementById("chatbot-button");
      let isDragging = false;
      let startX, startY;

      button.addEventListener("mousedown", (e) => {
        isDragging = true;
        startX = e.clientX - button.offsetLeft;
        startY = e.clientY - button.offsetTop;
      });

      document.addEventListener("mousemove", (e) => {
        if (!isDragging) return;
        button.style.left = `${e.clientX - startX}px`;
        button.style.top = `${e.clientY - startY}px`;
      });

      document.addEventListener("mouseup", () => {
        if (!isDragging) return;
        isDragging = false;

        // 检查按钮的位置
        const rect = button.getBoundingClientRect();
        if (rect.top < 620 || rect.left < 400) {
          // 复位按钮位置
          button.style.left = "initial";
          button.style.top = "initial";
        }
      });
    },
  },
};
